#include "config.h"
#include <myHeader.h>
#include <string.h>
#define MAX_LEN 128
int getParaMeterHelper(char *key,char *value){                                  
    FILE *pConfigFile=fopen("config.ini","r");
    ERROR_CHECK(pConfigFile,NULL,"ConfigFile open");

    char line[4096];
    char *lineKey=NULL;
    char *lineVal=NULL;
    while(1){
        memset(line,0,sizeof(line));

        char *res=fgets(line,sizeof(line),pConfigFile);
        if(!res){
            return -1;
        }
        line[strcspn(line, "\n")] = '\0';
        char *savePtr=NULL;
        lineKey=strtok_r(line,"=",&savePtr);
        if(!strcmp(lineKey,key)){
            lineVal=strtok_r(NULL,"=",&savePtr);
            memcpy(value,lineVal,strlen(lineVal));
            return 0;
        }
    }
}

int getParaMeter(configUsrInfo_t *pConfigFile){
   getParaMeterHelper("addr",pConfigFile->addr);
   getParaMeterHelper("port",pConfigFile->port);
   getParaMeterHelper("MySQLUsrName",pConfigFile->MySQLUsrName);
   getParaMeterHelper("MySQLPasswd",pConfigFile->MySQLPasswd);
   getParaMeterHelper("database",pConfigFile->database);
   getParaMeterHelper("workerNum",pConfigFile->workerNum);
   return 0;
}

